#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<stack>

using namespace std;

bool isvalid(char* s)
{
	stack<char> st;
	while (*s != '\0')
	{
		switch (*s)
		{
		case '{':
		case '[':
		case '(':
		case '<':
		{
			st.push(*s);
			++s;

			break;
		}
		case '}':
		case ']':
		case ')':
		case '>':
		{
			if (st.empty())
			{
				return false;
			}

			char top = st.top();
			st.pop();

			if ((*s == '}' && top != '{')
				|| (*s == ']' && top != '[')
				|| (*s == ')' && top != '(')
				|| (*s == '>' && top != '<'))
			{
				return false;
			}
			else
				++s;
			break;
		}
		default:
			break;
		}
	}
	bool ret = st.empty();
	return ret;
}
int main()
{
	ios::sync_with_stdio(false);
	cout.tie(NULL);

	int n;
	while (scanf("%d", &n) && n)
	{
		char str[20001];
		scanf("%s", str);

		int ret = isvalid(str);
		if (ret == 1)
			cout << "Yes" << endl;
		else
			cout << "No" << endl;
	}
	return 0;
}